function getUrl(){
    var apiUrl = (window.location.protocol === "https:" ? "https:" : "http:") + "//a1.easemob.com"
    var xmppUrl = "//im-api-v2.easemob.com/ws"
    if(window.location.href.indexOf("www.test.com") !== -1 ){
        apiUrl = (window.location.protocol === "https:" ? "https:" : "http:") + "//a1.easemob.com"
        xmppUrl = (window.location.protocol === "https:" ? "https:" : "http:") + "//im-api-v2.easemob.com/ws"
    }
    else if(window.location.href.indexOf("172.17.1.95") !== -1){
        apiUrl = (window.location.protocol === "https:" ? "https:" : "http:") + "//a1.easemob.com"
        xmppUrl = (window.location.protocol === "https:" ? "https:" : "http:") + "//im-api-v2.easemob.com/ws"
    }
    else if(window.location.href.indexOf("localhost") !== -1){
        apiUrl = (window.location.protocol === "https:" ? "https:" : "http:") + "//a1.easemob.com"
        xmppUrl = (window.location.protocol === "https:" ? "https:" : "http:") + "//im-api-v2.easemob.com/ws"
    }
    return {
        apiUrl: apiUrl,
        xmppUrl: xmppUrl
    }
}

function getconfig(){
	return {
		/*
		 * XMPP server
		 */
		xmppURL: getUrl().xmppUrl,
		/*
		 * Backend REST API URL
		 */
		apiURL: getUrl().apiUrl,
		  
		/*
		 * Application AppKey
		 */
		//appkey:"gdpwq123#ceshi",
		appkey: "1113200507065018#test",
		/*
		 * Application Host
		 */
		Host: "easemob.com",
		/*
		 * Whether to use HTTPS
		 * @parameter {Boolean} true or false
		 */
		https: true,
		isHttpDNS: false,
		/*
		 * isMultiLoginSessions
		 * true: A visitor can sign in to multiple webpages and receive messages at all the webpages.
		 * false: A visitor can sign in to only one webpage and receive messages at the webpage.
		 */
		isMultiLoginSessions: true,
		/**
		 * Whether to use window.doQuery()
		 * @parameter {Boolean} true or false
		 */
		isWindowSDK: false,
		/**
		 * isSandBox=true:  xmppURL: 'im-api.sandbox.easemob.com',  apiURL: '//a1.sdb.easemob.com',
		 * isSandBox=false: xmppURL: 'im-api.easemob.com',          apiURL: '//a1.easemob.com',
		 * @parameter {Boolean} true or false
		 */
		isSandBox: false,
		/**
		 * Whether to console.log in strophe.log()
		 * @parameter {Boolean} true or false
		 */
		isDebug: true,
		/**
		 * Whether to show logs in strophe
		 * @parameter {Boolean} true or false
		 */
		isStropheLog: false,
		/**
		 * will auto connect the xmpp server autoReconnectNumMax times in background when client is offline.
		 * won't auto connect if autoReconnectNumMax=0.
		 */
		autoReconnectNumMax: 5,
		/**
		 * the interval secons between each atuo reconnectting.
		 * works only if autoReconnectMaxNum >= 2.
		 */
		autoReconnectInterval: 2,
		/**
		 * webrtc supports WebKit and https only
		 */
		isWebRTC: true,//window.RTCPeerConnection && /^https\:$/.test(window.location.protocol),
		/**
		 *  cn: chinese
		 *  us: english
		 */
		i18n: "us",
		/*
		 * Set to auto sign-in
		 */
		isAutoLogin: true,
		/**
		 * Size of message cache for person to person
		 */
		p2pMessageCacheSize: 500,
		/**
		 * When a message arrived, the receiver send an ack message to the
		 * sender, in order to tell the sender the message has delivered.
		 * See call back function onReceivedMessage
		 */
		delivery: true,
		/**
		 * Size of message cache for group chating like group, chatroom etc
		 */
		groupMessageCacheSize: 200,
		/**
		 * 5 actual logging methods, ordered and available:
		 * 'TRACE', 'DEBUG', 'INFO', 'WARN', 'ERROR'
		 */
		
		loglevel: "ERROR",
		
		/**
		 * enable localstorage for history messages
		 */
		enableLocalStorage: true
	}
}

/**
 * git do not control webim.config.js
 * everyone should copy webim.config.js.demo to webim.config.js
 * and have their own configs.
 * In this way , others won't be influenced by this config while git pull.
 *
 */

// for react native
// var location = {
//     protocol: "https"
// }






function getemoji(){
	return  {
		path: "/statics/sp/img/faces/",
		map: {
			"[):]": "ee_1.png",
			"[:D]": "ee_2.png",
			"[;)]": "ee_3.png",
			"[:-o]": "ee_4.png",
			"[:p]": "ee_5.png",
			"[(H)]": "ee_6.png",
			"[:@]": "ee_7.png",
			"[:s]": "ee_8.png",
			"[:$]": "ee_9.png",
			"[:(]": "ee_10.png",
			"[:'(]": "ee_11.png",
			"[<o)]": "ee_12.png",
			"[(a)]": "ee_13.png",
			"[8o|]": "ee_14.png",
			"[8-|]": "ee_15.png",
			"[+o(]": "ee_16.png",
			"[|-)]": "ee_17.png",
			"[:|]": "ee_18.png",
			"[*-)]": "ee_19.png",
			"[:-#]": "ee_20.png",
			"[^o)]": "ee_21.png",
			"[:-*]": "ee_22.png",
			"[8-)]": "ee_23.png",
			"[(|)]": "ee_24.png",
			"[(u)]": "ee_25.png",
			"[(S)]": "ee_26.png",
			"[(*)]": "ee_27.png",
			"[(#)]": "ee_28.png",
			"[(R)]": "ee_29.png",
			"[({)]": "ee_30.png",
			"[(})]": "ee_31.png",
			"[(k)]": "ee_32.png",
			"[(F)]": "ee_33.png",
			"[(W)]": "ee_34.png",
			"[(D)]": "ee_35.png"
		}
	};
}
function parseEmoji(msg){ 
	console.log('啧啧啧')
	if(typeof getemoji() === "undefined" || typeof getemoji().map === "undefined"){
		return msg;
	}
	var emoji = getemoji(),
		reg = null;
	var msgList = [];
	var objList = [];
	for(var face in emoji.map){
		if(emoji.map.hasOwnProperty(face)){
			while(msg.indexOf(face) > -1){
				msg = msg.replace(face, "^" + emoji.map[face] + "^");
			}
		}
	}
	var ary = msg.split("^");
	console.log(ary)
	var reg = /^e.*g$/;
	for(var i = 0; i < ary.length; i++){
		if(ary[i] != ""){
			msgList.push(ary[i]);
		}
	}
	for(var i = 0; i < msgList.length; i++){
		if(reg.test(msgList[i])){
			var obj = {};
			obj.data = msgList[i];
			obj.type = "emoji";
			objList.push(obj);
		}
		else{
			var obj = {};
			obj.data = msgList[i];
			obj.type = "txt";
			objList.push(obj);
		}
	}
	return objList;
}